package com.ocean.web.controller.product;

import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.core.page.TableDataInfo;
import com.ocean.common.utils.DateUtils;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import com.ocean.elementdict.domain.OElementDict;
import com.ocean.elementdict.service.IOElementDictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author msy
 * @date 2023/2/23
 */
@Controller
@RequestMapping("product/elementDict")
public class OElementDictController extends BaseController {
    String prefix = "/product/elementDict";

    @Autowired
    private IOElementDictService elementDictService;

    @RequiresPermissions("product:elementDict:view")
    @GetMapping
    public String elementDict(){
        return prefix + "/elementDict";
    }

    /**
     * 列表查询
     * @param elementDict
     * @return
     */
    @ResponseBody
    @PostMapping("/list")
    public TableDataInfo list(OElementDict elementDict){
        startPage();
        List<OElementDict> result = elementDictService.selectOElementDictList(elementDict);
        return getDataTable(result);
    }

    /**
     * 录入——跳转
     * @return
     */
    @RequiresPermissions("product:elementDict:add")
    @GetMapping("add")
    public String add(ModelMap mmap){
        List<String> elementEn = elementDictService.getElementEn();
        mmap.put("elementEn",elementEn);
        return prefix + "/add";
    }

    /**
     * 新增
     * @param elementDict
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public AjaxResult add(OElementDict elementDict){
        return toAjax(elementDictService.insertElementDict(elementDict));
    }

    /**
     * 修改——跳转
     * @param id
     * @param mmap
     * @return
     */
    @RequiresPermissions("product:elementDict:edit")
    @GetMapping("edit/{id}")
    public String edit(@PathVariable String id, ModelMap mmap){
        OElementDict elementDict = elementDictService.selectElementDictById(id);
        mmap.put("elementDict",elementDict);
        List<String> elementEn = elementDictService.getElementEn();
        mmap.put("elementEn",elementEn);
        return prefix + "/edit";
    }

    /**
     * 修改
     * @param elementDict
     * @return
     */
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult edit(OElementDict elementDict){
        return toAjax(elementDictService.updateElementDict(elementDict));
    }

    /**
     * 详情
     * @param id
     * @param mmap
     * @return
     */
    @RequiresPermissions("product:elementDict:detail")
    @GetMapping("detail/{id}")
    public String detail(@PathVariable String id, ModelMap mmap){
        OElementDict elementDict = elementDictService.selectElementDictById(id);
        mmap.put("elementDict",elementDict);
        return prefix + "/detail";
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @RequiresPermissions("product:elementDict:remove")
    @PostMapping("remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(elementDictService.deleteElementDictByIds(ids));
    }
}
